<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/24/024
 * Time: 20:37
 */

namespace app\admin\model;

use think\facade\Session;

class Login extends \think\Model
{
    protected $table = 'sy_users';
    /**
     * 登陆
     * @param $post
     * @return bool
     */
    public function _login($post){
        $condition = [
            'u.user_name'=>trim($post['name']),
            'u.password'=> createPassword(trim($post['pwd'])),
        ];
        $ture_verify = Session::get('verify');
        $verify = strtolower(str_replace(' ', '', trim($post['code'])));
        if(strcmp($ture_verify, $verify)){
            $this->error = '验证码错误';
            return false;
        }
        $admin = $this->alias('u')
            ->field('u.*, r.role_name')
            ->join("role r", 'r.id = u.role_id', 'LEFT')
            ->where($condition)
            ->find();
        if(empty($admin)){
            $this->error = '用户名或密码错误';
            return false;
        }
        $admin_info = $this->alias('u')
            ->field('u.*, r.role_name')
            ->join("role r", 'r.id = u.role_id', 'LEFT')
            ->where($condition)
            ->find()
            ->toArray();
        Session::set('admin', $admin_info);
        return true;
    }


    


    


}